home *** CD-ROM | disk | FTP | other *** search
- /* $VER: EqFiles.rexx 1.8 (11.10.98)
- */
-
-
- /* Filenames of external programs */
- /*
- cmp='HD0:OTHER/C/Cmp'
- */
- /* If the routine does not find external program(s), uncomment the above and insert your path(s) */
-
-
- /* Parsing routine */
- parse upper arg template
- occ1=pos('"',template)
- if occ1=0 then parse var template dir1 dir2 opt1 opt2 .
- else do
- occ2=pos('"',template,occ1+1)
- if occ2=0 then signal error1
- else do
- occ3=pos('"',template,occ2+1)
- select
- when occ3=0 & occ1=1 then do
- parse var template '"'dir1'"' dir2 opt1 opt2 .
- end
- when occ1~=1 then do
- parse var template dir1 '"'dir2'"' opt1 opt2 .
- dir1=trim(dir1)
- if dir2=='' then dir2='""'
- end
- otherwise do
- occ4=pos('"',template,occ3+1)
- if occ4=0 then signal error1
- parse var template '"'dir1'"' try '"'dir2'"' opt1 opt2 .
- if try~='' then signal error2
- if dir2=='' then dir2='""'
- end
- end
- end
- end
- select
- when dir1='?' then signal template
- when dir1=':' ^ dir1='/' ^ dir2=':' ^ dir2='/' then signal error3
- when dir1='""' ^ dir1=='' then dir1=pragma('D')
- when left(dir1,1)='"' & right(dir1,1)='"' then dir1=substr(dir1,2,length(dir1)-2)
- when exists(dir1)=0 then signal error4
- when open('test',dir1,'read')=1 then signal error5
- otherwise nop
- end
- olddir=pragma('D',dir1)
- dir1=pragma('D',pragma('D',dir1))
- if right(dir1,1)~=":" & right(dir1,1)~="/" then dir1=dir1||"/"
- call pragma('D',olddir)
- select
- when dir2='DELETE' ^ dir2='ALL' then do
- opt2=opt1
- opt1=dir2
- dir2=dir1
- end
- when dir2=='' then dir2=dir1
- when dir2='""' then dir2=olddir
- when left(dir2,1)='"' & right(dir2,1)='"' then dir2=substr(dir2,2,length(dir2)-2)
- when exists(dir2)=0 then signal error6
- when open('test',dir2,'read')=1 then signal error7
- otherwise nop
- end
- call pragma('D',dir2)
- dir2=pragma('D',pragma('D',dir2))
- if right(dir2,1)~=":" & right(dir2,1)~="/" then dir2=dir2||"/"
- diff=compare(dir1,dir2)-1
- if opt1~='' & opt1~='DELETE' & opt1~='ALL' then signal error8
- if opt2~='' & opt2~='DELETE' & opt2~='ALL' then signal error9
- if opt1=opt2 then opt2=''
-
-
- /* Main program */
- address command
- if dir1=dir2 then do
- if opt1='' & opt2='' then say ' Scanning directory "'dir1'"'
- else say ' Scanning directory "'dir1'" with option(s) 'opt1 opt2''
- if opt1='ALL' | opt2='ALL' then do
- 'List >T:FileList1 "'dir1'" lformat="%8l %p%-s" Files All'
- end
- else do
- 'List >T:FileList1 "'dir1'" lformat="%8l %p%-s" Files'
- end
- call open('in1','T:FileList1','read')
- line1=readln('in1')
- errdir=dir1
- if EOF('in1') then signal error10
- call close('in1')
- 'Sort T:FileList1 To T:FileList1 Case ColStart 10'
- 'Copy T:FileList1 To T:FileList2'
- end
- else do
- if opt1='' & opt2='' then say ' Scanning directories "'dir1'" and "'dir2'"'
- else say ' Scanning directories "'dir1'" and "'dir2'" with option(s) 'opt1 opt2''
- if opt1='ALL' | opt2='ALL' then do
- 'List >T:FileList1 "'dir1'" lformat="%8l %p%-s" Files All'
- 'List >T:FileList2 "'dir2'" lformat="%8l %p%-s" Files All'
- end
- else do
- 'List >T:FileList1 "'dir1'" lformat="%8l %p%-s" Files'
- 'List >T:FileList2 "'dir2'" lformat="%8l %p%-s" Files'
- end
- call open('in1','T:FileList1','read')
- line1=readln('in1')
- errdir=dir1
- if EOF('in1') then signal error10
- call close('in1')
- call open('in2','T:FileList2','read')
- line2=readln('in2')
- errdir=dir2
- if EOF('in2') then signal error10
- call close('in2')
- 'Sort T:FileList1 To T:FileList1 Case ColStart 10'
- 'Sort T:FileList2 To T:FileList2 Case ColStart 10'
- end
- call open('in1','T:FileList1','read')
- call open('in2','T:FileList2','read')
- do forever
- line1=readln('in1')
- if line1='' then leave
- len1=left(line1,8)
- call seek('in2',0,'B')
- do forever
- line2=readln('in2')
- if line2='' then leave
- len2=left(line2,8)
- if len1=len2 then do
- fname1=right(line1,length(line1)-9)
- fname2=right(line2,length(line2)-9)
- select
- when abbrev(dir1,dir2) & abbrev(fname2,dir1) then ineq=fname1<fname2
- when abbrev(dir2,dir1) & abbrev(fname1,dir2) then ineq=fname1<fname2
- when dir1=dir2 then ineq=fname1<fname2
- otherwise ineq=1
- end
- if ineq then do
- if exists(fname2)=1 then do
- cmp '"'fname1'" "'fname2'" DUMP 0 CHECKD >NIL:'
- if RC=0 then do
- str1=delstr(fname1,1,length(dir1))
- str2=delstr(fname2,1,length(dir2))
- say ''str1' == 'str2
- flag=1
- if opt1='DELETE' | opt2='DELETE' then do
- 'Echo " " NoLine'
- 'Delete "'fname2'" Force'
- say 'A'
- end
- end
- end
- end
- end
- end
- end
- call close('in2')
- call close('in1')
- 'Delete T:FileList1 T:FileList2 Quiet'
- if flag~=1 then say 'No equal files detected.'
- exit
-
-
- error1:
- say 'BImproper number of " delimiters!B'
- exit
-
-
- error2:
- say 'BIllegal input string!B'
- signal template
- exit
-
-
- error3:
- say 'BPlease do not use ":" and "/" abbreviations!B'
- exit
-
-
- error4:
- say 'B<dir1> "'dir1'" does not exist!B'
- exit
-
-
- error5:
- say 'B<dir1> "'dir1'" must be a directory!B'
- exit
-
-
- error6:
- say 'B<dir2> "'dir2'" does not exist!B'
- exit
-
-
- error7:
- say 'B<dir2> "'dir2'" must be a directory!B'
- exit
-
-
- error8:
- say 'BOption 'opt1' not allowed!B'
- exit
-
-
- error9:
- say 'BOption 'opt2' not allowed!B'
- exit
-
-
- error10:
- say 'BNo files in directory "'errdir'" !B'
- exit
-
-
- template:
- say 'BEqFiles V1.8 by Fulvio Peruggi - October 11, 1998B'
- say 'Usage: [rx] EqFiles[.rexx] [<dir1>] [<dir2>] [ALL] [DELETE]'
- say 'BScans all files in directories <dir1> and <dir2>, compares all pairs of'
- say ' files having the same size, and lists all pairs of equal files.'
- say 'Scans, compares, and lists all pairs of equal files in <dir1>, if'
- say ' <dir2>=<dir1> or if <dir2> is not specified.'
- say 'Command operations act on all subdirectories and their files if the'
- say ' optional parameter ALL is specified.'
- say 'Equal files found in <dir2> are deleted if the optional parameter DELETE'
- say ' is specified.B'
- exit
-